<?php

// @formatter:off
/**
 * @file links.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: links.php 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/extensions/AutoTagger/autotagger/links.php $
 */
// @formatter:on

include WC_E_AUTOTAGGER_ROOTDIR."/includes/AutoTagger.php";

class ActionControllerAutotaggerLinks extends WCActionController {
	//
	// Public methods.
	public function check() {
		$check = parent::check();

		if($check == WC_HTTPERROR_OK) {
			global $wcProfile;

			if(!$wcProfile->allowedTo(WC_PERM_AUTOTAGGER)) {
				global $errno;
				global $error;

				$check = WC_HTTPERROR_FORBIDDEN;
				$errno = $check;
				$error = "You have not enough privileges";
			}
		}

		return $check;
	}
	//
	// Protected methods.
	protected function subRun() {
		$ok = true;
		//
		// Loading global pointers.
		global $wcGroup;
		global $wcDirectory;

		$autoTagger = AutoTagger::I();

		WCViewInfoFactory::LoadInfo($wcDirectory, true);

		$items = $autoTagger->directoryTags($wcDirectory);
		uasort($items, "WCTag::NameSort");
		$directoryTags = array();
		foreach($items as $tag) {
			$directoryTags[] = array(
				"id" => $tag->id,
				"name" => $tag->name
			);
		}

		$this->_manager->directory_tags = $directoryTags;

		return $ok;
	}
}
